home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / MIXTREE.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  274 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include "globals.h"            // prototypes specific to this application
  27.  
  28. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  29. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  30. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  32.  
  33. // About dialog message table definition.
  34. MSD rgmsdAbout[] =
  35. {
  36.     {WM_COMMAND,    MsgAboutCommand},
  37.     {WM_INITDIALOG, MsgAboutInit}
  38. };
  39.  
  40. MSDI msdiAbout =
  41. {
  42.     sizeof(rgmsdAbout) / sizeof(MSD),
  43.     rgmsdAbout,
  44.     edwpNone
  45. };
  46.  
  47. // About dialog command table definition.
  48. CMD rgcmdAbout[] =
  49. {
  50.     {IDOK,     CmdAboutDone},
  51.     {IDCANCEL, CmdAboutDone}
  52. };
  53.  
  54. CMDI cmdiAbout =
  55. {
  56.     sizeof(rgcmdAbout) / sizeof(CMD),
  57.     rgcmdAbout,
  58.     edwpNone
  59. };
  60.  
  61. // Module specific "globals"  Used when a variable needs to be
  62. // accessed in more than on handler function.
  63.  
  64. HFONT hFontCopyright;
  65.  
  66. //
  67. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  68. //
  69. //  PURPOSE: Displays the "About" dialog box
  70. //
  71. //  PARAMETERS:
  72. //    hwnd      - Window handle
  73. //    wCommand  - IDM_ABOUT (unused)
  74. //    wNotify   - Notification number (unused)
  75. //    hwndCtrl  - NULL (unused)
  76. //
  77. //  RETURN VALUE:
  78. //
  79. //    Always returns 0 - Message handled
  80. //
  81. //  COMMENTS:
  82. //    To process the IDM_ABOUT message, call DialogBox() to display the
  83. //    about dialog box.
  84.  
  85. #pragma argsused
  86. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  87. {
  88.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  89.     return 0;
  90. }
  91.  
  92.  
  93. //
  94. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  95. //
  96. //  PURPOSE:  Processes messages for "About" dialog box.
  97. //
  98. //  PARAMETERS:
  99. //    hdlg     - window handle of the dialog box
  100. //    wMessage - type of message
  101. //    wparam   - message-specific information
  102. //    lparam   - message-specific information
  103. //
  104. //  RETURN VALUE:
  105. //    TRUE     - message handled
  106. //    FALSE    - message not handled
  107. //
  108. //  COMMENTS:
  109. //
  110. //     Display version information from the version section of the
  111. //     application resource.
  112. //
  113. //     Wait for user to click on "Ok" button, then close the dialog box.
  114. //
  115.  
  116. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  117. {
  118.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  119. }
  120.  
  121.  
  122. //
  123. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  124. //
  125. //  PURPOSE: To initialize the about box with version info from resources.
  126. //
  127. //  PARAMETERS:
  128. //    hwnd     - The window handing the message.
  129. //    uMessage - The message number. (unused).
  130. //    wparam   - Message specific data (unused).
  131. //    lparam   - Message specific data (unused).
  132. //
  133. //  RETURN VALUE:
  134. //    Always returns 0 - message handled.
  135. //
  136. //  COMMENTS:
  137. //    Uses the version apis to retrieve version information for
  138. //    each of the static text boxes in the about box.
  139. //
  140.  
  141. #pragma argsused
  142. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  143. {
  144.     #define POINTSIZE 8
  145.  
  146.     char  szFullPath[256];
  147.     DWORD dwVerHnd;
  148.     DWORD dwVerInfoSize;
  149.     HDC   hDC;
  150.     int   iLogPixelsY, iPointSize;
  151.  
  152.     // Center the dialog over the application window
  153.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  154.  
  155.     // Set the copyright font to something smaller than default
  156.     hDC = GetDC(hdlg);
  157.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  158.     ReleaseDC(hdlg, hDC);
  159.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  160.     iPointSize *= -1;
  161.  
  162.     hFontCopyright = CreateFont(iPointSize,
  163.                                 0, 0, 0,
  164.                                 FW_BOLD,
  165.                                 0, 0, 0, 0,
  166.                                 0, 0, 0, 0,
  167.                                 "Arial");
  168.  
  169.     SendDlgItemMessage(hdlg, 
  170.                        IDD_VERLAST, 
  171.                        WM_SETFONT, 
  172.                        (WPARAM)hFontCopyright,
  173.                        0L);
  174.  
  175.     // Get version information from the application
  176.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  177.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  178.     if (dwVerInfoSize)
  179.     {
  180.         // If we were able to get the information, process it:
  181.         HANDLE  hMem;
  182.         LPVOID  lpvMem;
  183.         char    szGetName[256];
  184.         int     cchRoot;
  185.         int     i;
  186.  
  187.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  188.         lpvMem = GlobalLock(hMem);
  189.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  190.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  191.         cchRoot = lstrlen(szGetName);
  192.  
  193.         // Walk through the dialog items that we want to replace:
  194.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  195.         {
  196.             BOOL  fRet;
  197.             UINT  cchVer = 0;
  198.             LPSTR lszVer = NULL;
  199.             char  szResult[256];
  200.  
  201.             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  202.             lstrcpy(&szGetName[cchRoot], szResult);
  203.             fRet = VerQueryValue(lpvMem, szGetName, (LPVOID) &lszVer, &cchVer);
  204.  
  205.             if (fRet && cchVer && lszVer)
  206.             {
  207.                 // Replace dialog item text with version info
  208.                 lstrcpy(szResult, lszVer);
  209.                 SetDlgItemText(hdlg, i, szResult);
  210.             }
  211.         }
  212.         GlobalUnlock(hMem);
  213.         GlobalFree(hMem);
  214.     }
  215.     return TRUE;
  216. }
  217.  
  218. //
  219. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  220. //
  221. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  222. //
  223. //  PARAMETERS:
  224. //    hwnd     - The window handing the message.
  225. //    uMessage - The message number. (unused).
  226. //    wparam   - Message specific data (unused).
  227. //    lparam   - Message specific data (unused).
  228. //
  229. //  RETURN VALUE:
  230. //    Always returns 0 - message handled.
  231. //
  232. //  COMMENTS:
  233. //    Uses this DipsCommand function defined in wndproc.c combined
  234. //    with the cmdiAbout structure defined in this file to handle
  235. //    the command messages for the about dialog box.
  236. //
  237.  
  238. #pragma argsused
  239. LRESULT MsgAboutCommand(HWND   hwnd, 
  240.                         UINT   uMessage, 
  241.                         WPARAM wparam, 
  242.                         LPARAM lparam)
  243. {
  244.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  245. }
  246.  
  247. //
  248. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  249. //
  250. //  PURPOSE: Free the about box and related data.
  251. //
  252. //  PARAMETERS:
  253. //    hwnd     - The window handling the command.
  254. //    wCommand - The command to be handled (unused).
  255. //    wNotify  - Notification number (unused)
  256. //    hwndCtrl - NULL (unused).
  257. //
  258. //  RETURN VALUE:
  259. //    Always returns TRUE.
  260. //
  261. //  COMMENTS:
  262. //    Calls EndDialog to finish the dialog session.
  263. //
  264.  
  265. #pragma argsused
  266. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  267. {
  268.     if (hFontCopyright)
  269.        DeleteObject(hFontCopyright);
  270.  
  271.     EndDialog(hdlg, TRUE);          // Exit the dialog
  272.     return TRUE;
  273. }
  274.